<?php

session_start();

$op = $_GET['op'];
$id = $_GET['id'];

$isSignin = isset($_SESSION['user'])? true : false;
$user = isset($_SESSION['user'])?$_SESSION['user'] : null;

$cart = isset($_SESSION['cart'])?$_SESSION['cart'] : [];

for ($i=0; $i <count($cart) ; $i++) { 
	if ($cart[$i]['id'] == $id) {
		if ($op == 1) {
			if ($cart[$i]['num'] > 1) {
				$cart[$i]['num'] -=1;
			}else{
				array_splice($cart, $i,1);
			}
		}else{
			$cart[$i]['num'] +=1;
		}
		break;
	}
}

$_SESSION['cart'] = $cart;
header('Location:../public/cart.php');